/**
 * 
 */
package cn.ivicar.sim.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;

import cn.com.carsmart.exception.CarsmartException;
import cn.com.carsmart.ws.ibatis.model.BaseExample;
import cn.com.carsmart.ws.model.SimChargeRecord;
import cn.com.carsmart.ws.service.SimChargeRecordManager;

/**
 * @author liurunbin 2017年7月9日 cn.ivicar.sim.service
 */
public class SimChargeRecordService {
	private static transient final Logger LOGGER = LoggerFactory.getLogger(SimChargeRecordService.class);

	@Inject
	private SimChargeRecordManager simChargeRecordManager;

	public SimChargeRecord getChargeRecordById(Long chargeId) {
		SimChargeRecord query = new SimChargeRecord();
		query.setChargeId(chargeId);
		List<SimChargeRecord> list = simChargeRecordManager.listByExample(query);
		if (list == null || list.isEmpty()) {
			return null;
		}

		return list.get(0);
	}

	public List<SimChargeRecord> getList(Long customerId, Integer pageIndex, Integer pageSize) {
		BaseExample example = simChargeRecordManager.getExample();
		example.or().andPropertyEqualTo(customerId, "customerId").andPropertyEqualTo(false, "isDeleted");
		example.setLimitStart(pageIndex * pageSize);
		example.setLimitCount(pageSize);
		example.setOrderByClause("created desc");

		return simChargeRecordManager.listByBaseExample(example);

	}

	public void delete(Long chargeId) throws CarsmartException {
		SimChargeRecord query = this.getChargeRecordById(chargeId);
		if (query == null) {
			return;
		}
		query.setIsDeleted(true);
		simChargeRecordManager.update(query);
	}
}
